package mb.config;
/**
 *
 * @author dac.nguyentatdfgdfgdfg
 * Configuration handling
 */
import java.util.Properties;
import java.io.FileInputStream;

public class Config {
    boolean bIsInitialized = false;
    FileInputStream objConfigStream = null;
    Properties objProps = null;
    
    public void init(String sPropertyFileName) throws Exception{
        try{
            objProps = new Properties();
            objConfigStream = new FileInputStream(sPropertyFileName);
            objProps.load(objConfigStream); 
            bIsInitialized = true;
        }
        catch(Exception ex){
            bIsInitialized = false;
            throw ex;
        }
    }
    public void deinit(){
        if(bIsInitialized){
            try{
                objProps = null;
                objConfigStream.close();
                bIsInitialized = false;
            }
            catch(Exception ex){
                bIsInitialized = false;
            }
        }
    }
    public String getProperty(String sPropertyName) throws Exception{
        if(!bIsInitialized) throw new Exception ("Configuration not initialized!");
        String sValue = objProps.getProperty(sPropertyName);
        return sValue;
    }
    public String[] getProperties(String sPropertyName,String sSeperator)  throws Exception{
        if(!bIsInitialized) throw new Exception ("Configuration not initialized!");
        String sValue = objProps.getProperty(sPropertyName);
        String[] asReturnValue = sValue.split("\\" + sSeperator);
        return asReturnValue;
    }
}
